package hiatao.puzzle.fragment;

import haitao.puzzle.R;
import hiatao.puzzle.activity.UserActivity;
import hiatao.puzzle.adapter.ListUserAdapter;
import hiatao.puzzle.config.URLS;
import hiatao.puzzle.entity.User;
import hiatao.puzzle.utils.Tools;
import hiatao.puzzle.widget.XListView;
import java.util.ArrayList;
import java.util.List;

import com.desmond.parallaxheaderviewpager.TestActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class RankAllFragment extends Fragment{

	
	private View rootView;
    private XListView listView = null;
    private ListUserAdapter adapter;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.xlistview, container, false);
		findView();
		init();
		return rootView;
	}

	private void init() {
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				Intent intent = new Intent();
				intent.setClass(getActivity(), TestActivity.class);
				intent.putExtra("SELF", false);
				intent.putExtra("USER", (User)adapter.getItem(position-2));
				getActivity().startActivity(intent);
			}
		});
	}

	private void findView() {
		listView = (XListView) rootView.findViewById(R.id.listview);
		View header = getActivity().getLayoutInflater().inflate(R.layout.rank_header, null);
		TextView tv =(TextView) header.findViewById(R.id.rank_tv);
		tv.setText("你在当前所有玩家排名1025名");
		listView.addHeaderView(header);
		adapter = new ListUserAdapter(getActivity(), null);
		listView.setAdapter(adapter);
		listView.setPullRefreshEnable(false);
		listView.setPullLoadEnable(false);
		adapter.appendToList(testData());
	}
	private List<User> testData() {
		List<User> userList = new ArrayList<User>();
		User u1= new User();
		u1.setName("100g小土豆");
		u1.setIntro("爱拼才会赢！");
		u1.setHeadUrl(URLS.BASE_USER+1+".png");
		u1.setFocus(false);
		u1.setZuanNum(350);
		userList.add(u1);
		User u2= new User();
		u2.setName("Alvin QI");
		u2.setIntro("世界那么大，只要有爱就没问题");
		u2.setHeadUrl(URLS.BASE_USER+2+".png");
		u2.setFocus(true);
		u2.setZuanNum(345);
		userList.add(u2);
		User u3= new User();
		u3.setName("Double ice");
		u3.setIntro("拼图的胜利在于速度。");
		u3.setHeadUrl(URLS.BASE_USER+3+".png");
		u3.setFocus(true);
		u3.setZuanNum(340);
		userList.add(u3);
		
		User u4= new User();
		u4.setName("Chenlina");
		u4.setIntro("这是一个有趣的平台，你觉得呢？");
		u4.setHeadUrl(URLS.BASE_USER+4+".png");
		u4.setFocus(true);
		u4.setZuanNum(335);
		userList.add(u4);
		
		User u5= new User();
		u5.setName("IXDC潘");
		u5.setIntro("你必须非常努力，才能让人看起来毫不费力");
		u5.setHeadUrl(URLS.BASE_USER+5+".png");
		u5.setFocus(true);
		u5.setZuanNum(320);
		userList.add(u5);
		
		
		User u6= new User();
		u6.setName("Tracy");
		u6.setIntro("友谊是一棵可以庇荫的树。");
		u6.setHeadUrl(URLS.BASE_USER+6+".png");
		u6.setFocus(true);
		u6.setZuanNum(300);
		userList.add(u6);
		
		User u7= new User();
		u7.setName("超级丹");
		u7.setIntro("真正的才智是刚毅的意志");
		u7.setHeadUrl(URLS.BASE_USER+7+".png");
		u7.setFocus(true);
		u7.setZuanNum(289);
		userList.add(u7);
		
		User u8= new User();
		u8.setName("Olivia");
		u8.setIntro("不达成功誓不休");
		u8.setHeadUrl(URLS.BASE_USER+15+".png");
		u8.setFocus(false);
		u8.setZuanNum(280);
		userList.add(u8);
		
		User u9= new User();
		u9.setName("美啊✌");
		u9.setIntro("笨蛋自以为聪明，聪明人才知道自己是笨蛋");
		u9.setHeadUrl(URLS.BASE_USER+16+".png");
		u9.setFocus(true);
		u9.setZuanNum(270);
		userList.add(u9);
		
		User u10= new User();
		u10.setName("Johan");
		u10.setIntro("成功的秘诀，在永不改变既定的目的");
		u10.setHeadUrl(URLS.BASE_USER+17+".png");
		u10.setFocus(true);
		u10.setZuanNum(268);
		userList.add(u10);
		
		User u11= new User();
		u11.setName("Jamie婕");
		u11.setIntro("从不浪费时间的人，没有工夫抱怨时间不够");
		u11.setHeadUrl(URLS.BASE_USER+18+".png");
		u11.setFocus(true);
		u11.setZuanNum(265);
		userList.add(u11);
		
		
		return userList;
	}
}
